/**
  * filename:       adm-facade.js
  * description:    Application Layout
  */

Ext.namespace("Layout");
Layout.base = function(){
    Ext.QuickTips.init();

    var cfgStore = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({url: '/admin/node-configs/'}),
	    restful: true,
	    reader: new Ext.data.JsonReader({root: 'data',totalProperty: '',idProperty: 'Id'},[ 
		    {name: 'Id', type: 'int', mapping: 'Id'},
		    {name: 'Name', type: 'string', mapping: 'Name'},
			{name: 'Controller', type: 'string', mapping: 'Controller'}
		])
	});
    cfgStore.load();
    
    var layoutStore = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({url: '/admin/layout/'}),
	    restful: true,
	    reader: new Ext.data.JsonReader({root: 'data',totalProperty: '',idProperty: 'Id'},[ 
		    {name: 'Id', type: 'int', mapping: 'Id'},
			{name: 'Layout', type: 'string', mapping: 'Layout'},
		    {name: 'Name', type: 'string', mapping: 'Name'}
		])
	});
    layoutStore.load();
    
    var tab =  new Ext.TabPanel({
    	margins: '0 0 5 0',
        region: 'center', // a center region is ALWAYS required for border layout
        deferredRender: false,
        enableTabScroll: true,
        activeTab: 0,     // first tab initially active
        items: [ {
            contentEl: 'center2',
            title: 'Информация',
            autoScroll: true,
            closeable: true
        }]
    });
    
    var statusBar = new Ext.ux.StatusBar({
        region: 'south',
        text: 'Готово',
        iconCls: 'x-status-valid',
        defaultText: '', 
        defaultIconCls: ''
    });
    
    var tree = new Nippy.Components.SiteTree({layoutStore: layoutStore, cfgStore: cfgStore, tab: tab, sb:statusBar, root: rootNode});
    ////////////////////////////////////

    return {
        init: function(){
    		new Ext.Viewport({
		        layout: 'border',
		        items: [
		        new Ext.BoxComponent({
		            region: 'north',
		            height: 32, // give north and south regions a height
		            contentEl: 'north'
		        }),{
		            region: 'west',
		            id: 'west-panel', // see Ext.getCmp() below
		            title: 'Дерево сайта',
		            split: true,
		            width: 200,
		            minSize: 175,
		            maxSize: 400,
		            collapsible: true,
		            margins: '0 0 5 5',
		            items: [tree],
					autoScroll: true
		        }
		        ,statusBar
		        ,tab]
		    });
        }
    };
}();
Ext.onReady(Layout.base.init, Layout.base);
